class Observeable {
  constructor (data) {
    this.walk(data)
  }

  walk (data) {
    if (!data || typeof data !== 'object') return;
    Object.keys(data).forEach(key => {
      this.defineReactive(data, key, data[key]);
    })
  }

  defineReactive (target, key, val) {

    let dep = new Dep()
    let that = this;
    this.walk(val);
    Object.defineProperty(target, key, {
      enumerable: true,
      configurable: true,
      get () {
        Dep.target && dep.addSub(Dep.target);
        return val;
      },
      set (newValue) {
        if (newValue === val) return;
        val = newValue;
        that.walk(newValue);
        dep.notify();
      }
    })
  }
}